/*
 * Copyright 2002-2018 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.aopalliance.intercept;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
 * 在通往目标的途中拦截接口上的调用。
 * 这些是嵌套在目标的 "顶部"。
 *
 * 用户应该实现{@link #invoke(MethodInvocation)}方法来修改原来的行为。
 * 方法来修改原来的行为。
 * 例如，下面这个类实现了一个追踪拦截器（追踪所有对拦截的方法）。
 *
 * <pre class=code>
 * class TracingInterceptor implements MethodInterceptor {
 *   Object invoke(MethodInvocation i) throws Throwable {
 *     System.out.println("method "+i.getMethod()+" is called on "+
 *                        i.getThis()+" with args "+i.getArguments());
 *     Object ret=i.proceed();
 *     System.out.println("method "+i.getMethod()+" returns "+ret);
 *     return ret;
 *   }
 * }
 * </pre>
 *
 * @author Rod Johnson
 */
@FunctionalInterface
public interface MethodInterceptor extends Interceptor {

	/**
	 * 实现这个方法，在调用之前和之后进行额外的处理。
	 * 调用后进行额外的处理。有礼貌的实现肯定会
	 * 喜欢调用{@link Joinpoint#proceed()}。
	 * @param invocation 方法调用的连接点
	 * @return {@link Joinpoint#proceed()}的调用结果。可能被拦截器拦截。
	 * @throws Throwable 如果拦截器或目标对象抛出一个异常
	 */
	@Nullable
	Object invoke(@Nonnull MethodInvocation invocation) throws Throwable;

}
